package com.hctg.forced2sleep.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hctg.forced2sleep.R;

import org.jetbrains.annotations.NotNull;

/**
 * description: 描述
 * company    :
 *
 * @author : ldf
 * date       : 2024/12/1 on 18
 * @version 1.0
 */
public class VipBuyActivityAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private int selectedItem = 0;

    public VipBuyActivityAdapter() {
        super(R.layout.vip_price_item);
        setOnItemClickListener((adapter, view, position) -> {
            if (position != selectedItem) {
                int oldPos = selectedItem;
                selectedItem = position;
                notifyItemChanged(oldPos);
                notifyItemChanged(position);
            }
        });
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, String item) {
        boolean isSelectedItem = holder.getAbsoluteAdapterPosition() == selectedItem;
        holder.setText(R.id.tv_title, "1个月会员")
                .setText(R.id.tv_desc, "31天, 希望能帮助到你, 感谢有你")
                .setText(R.id.tv_price, "20")
                .setText(R.id.tv_tag, "特惠")
                .setVisible(R.id.tv_tag, isSelectedItem);
        View view = holder.getView(R.id.root);
        view.setSelected(isSelectedItem);
    }
}
